package com.rjkj.medicalwaste.paging

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.rjkj.medicalwaste.bean.TestBean
import java.lang.Exception

class BoxListPagingSource(val int: Int):PagingSource<Int,TestBean>() {
    override fun getRefreshKey(state: PagingState<Int, TestBean>): Int? {
        return null
    }
    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, TestBean> {
        return try {
            val page = params.key?:1
            val pageSize = params.loadSize
            val list = listOf(
                TestBean("a+$int"),
                TestBean("b+$int"),
                TestBean("c+$int"),
                TestBean("d+$int"),
                TestBean("e+$int"),
                TestBean("f+$int"))
//            val prevKey = if (page > 1) page - 1 else null
//            val nextKey = if (list.isNotEmpty()) page + 1 else null
//            return LoadResult.Page(list,prevKey,nextKey)
            return LoadResult.Page(list,null,null)
        }catch (e:Exception){
            LoadResult.Error(e)
        }
    }
}